package com.yq.ylmall.activity.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yq.ylmall.activity.service.IActivityInfoService;
import com.yq.ylmall.dto.activity.ActivityInfoDto;
import com.yq.ylmall.dto.activity.ActivityRuleDto;
import com.yq.ylmall.model.activity.ActivityInfo;
import com.yq.ylmall.result.Result;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author cherry
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/admin/activity/activityInfo")
@RequiredArgsConstructor
public class ActivityInfoController {
    private final IActivityInfoService activityInfoService;

    @ApiOperation(value = "分页条件查询活动")
    @PostMapping("/page")
    public Result<Object> list(@RequestBody ActivityInfoDto activityInfoDto){
        return Result.ok(activityInfoService.queryActivityInfo(activityInfoDto));
    }

    @ApiOperation(value = "添加活动规则")
    @PostMapping("/save")
    public Result<Object> save(@RequestBody ActivityRuleDto activityRuleDto){
        ActivityInfo activityInfo = new ActivityInfo();
        BeanUtils.copyProperties(activityRuleDto,activityInfo);
        activityInfoService.save(activityInfo);
        return Result.ok();
    }

    //营销活动规则相关接口
    //1 根据活动id获取活动规则数据
    @ApiOperation(value = "根据活动id获取活动规则数据")
    @GetMapping("findActivityRuleList/{id}")
    public Result findActivityRuleList(@PathVariable Long id){
        Map<String,Object> map = activityInfoService.findActivityRuleList(id);
        return Result.ok(map);
    }
    //2
}
